package com.ruoyi.web.controller.credit;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.credit.domain.EvaTaskDept;
import com.ruoyi.credit.service.IEvaTaskDeptService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务和部门关联Controller
 *
 * @author zhulei
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/credit/taskDept")
public class EvaTaskDeptController extends BaseController
{
    private String prefix = "credit/taskDept";

    @Autowired
    private IEvaTaskDeptService evaTaskDeptService;

    @RequiresPermissions("credit:taskDept:view")
    @GetMapping()
    public String taskDept()
    {
        return prefix + "/taskDept";
    }

    /**
     * 查询任务和部门关联列表
     */
    @RequiresPermissions("credit:taskDept:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EvaTaskDept evaTaskDept)
    {
        startPage();
        List<EvaTaskDept> list = evaTaskDeptService.selectEvaTaskDeptList(evaTaskDept);
        return getDataTable(list);
    }

    /**
     * 导出任务和部门关联列表
     */
    @RequiresPermissions("credit:taskDept:export")
    @Log(title = "任务和部门关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EvaTaskDept evaTaskDept)
    {
        List<EvaTaskDept> list = evaTaskDeptService.selectEvaTaskDeptList(evaTaskDept);
        ExcelUtil<EvaTaskDept> util = new ExcelUtil<EvaTaskDept>(EvaTaskDept.class);
        return util.exportExcel(list, "任务和部门关联数据");
    }

    /**
     * 新增任务和部门关联
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存任务和部门关联
     */
    @RequiresPermissions("credit:taskDept:add")
    @Log(title = "任务和部门关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EvaTaskDept evaTaskDept)
    {
        return toAjax(evaTaskDeptService.insertEvaTaskDept(evaTaskDept));
    }

    /**
     * 修改任务和部门关联
     */
    @RequiresPermissions("credit:taskDept:edit")
    @GetMapping("/edit/{taskId}")
    public String edit(@PathVariable("taskId") Long taskId, ModelMap mmap)
    {
        EvaTaskDept evaTaskDept = evaTaskDeptService.selectEvaTaskDeptByTaskId(taskId);
        mmap.put("evaTaskDept", evaTaskDept);
        return prefix + "/edit";
    }

    /**
     * 修改保存任务和部门关联
     */
    @RequiresPermissions("credit:taskDept:edit")
    @Log(title = "任务和部门关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EvaTaskDept evaTaskDept)
    {
        return toAjax(evaTaskDeptService.updateEvaTaskDept(evaTaskDept));
    }

    /**
     * 删除任务和部门关联
     */
    @RequiresPermissions("credit:taskDept:remove")
    @Log(title = "任务和部门关联", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(evaTaskDeptService.deleteEvaTaskDeptByTaskIds(ids));
    }
}
